package kr.saeildamil.androidstudy.ch12;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class SpinnerTest extends Activity {
	ArrayAdapter<CharSequence> adspin;
	boolean mInitSpinner;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_spinnertest);

		Spinner spin = (Spinner) findViewById(R.id.ch12_spinnertest_spin);
		/*spin.setPrompt("나라를 선택해라");*/

		adspin = ArrayAdapter.createFromResource(this, R.array.country,
				android.R.layout.simple_spinner_item);
		adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spin.setAdapter(adspin);
		/*spin.setSelection(5);
		int pos = spin.getSelectedItemPosition();
		Toast.makeText(this, "포지션은" + pos, Toast.LENGTH_LONG).show();*/

		spin.setOnItemSelectedListener(new OnItemSelectedListener() {
			public void onItemSelected(AdapterView<?> parent, View arg1,
					int position, long id) {
				if(mInitSpinner == false){
					mInitSpinner =true;
					return;
				}
				Toast.makeText(SpinnerTest.this, adspin.getItem(position),
						Toast.LENGTH_LONG).show();
			}

			public void onNothingSelected(AdapterView<?> parent) {
			}
		});

	}
}
